package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @Description: 公用常量
 * @Data: 2022/9/15 15:16
 * @Pacakge: com.qf.controller
 * @ClassName: UserController
 * @Author: fan
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping("/index")
    public String index(){
        return "index";
    }

    @RequestMapping("/login")
    public String login(User user,HttpSession httpSession){
        boolean login = userService.findUserByUserName(user,httpSession);
        System.out.println(login);
        if (login){
            return "redirect:/student/findAll";
        }else{
            return "redirect:/user/index";
        }
    }

    @RequestMapping("loginOut")
    public String loginOut(HttpSession httpSession){
        httpSession.removeAttribute("user");
        return "index";
    }


}
